package com.astruyk.battlegroundAndroid.data;

public class LatLonConverter {
	public static final double WORLD_Y = 4211200;
	public static final double ARC_Y = 70.1875;
	public static final double WORLD_X = 8640000;
	public static final double ARC_X = 180.0;
	
	public static double ConvertToGoogleLat(double y){
		return y / WORLD_Y * ARC_Y;
	}
	
	public static double ConvertToGoogleLon(double x){
		return x / WORLD_X * ARC_X;
	}
	
	private class LatLon{
		double x;
		double y;
		double ox;
		double oy;
		double glat;
		LatLonComponent lat;
		double glon;
		LatLonComponent lon;
		
		public LatLon(double x, double y){
			this.x = x;
			this.y = y;
			this.ox = Math.floor(x * 800);
			this.oy = Math.floor(y * 800);
			this.glat = y / WORLD_Y * ARC_Y;
			this.glon = x / WORLD_X * ARC_X;
			
			this.lat = new LatLonComponent(glat, "E", "W");
			this.lon = new LatLonComponent(glon, "N", "S");
		}
		
		private class LatLonComponent{
			private double coord;
			private String sign;
			private double deg;
			private double min;
			private double sec;
			
			public LatLonComponent(double coord, String posSign, String negSign){
				if(coord > 0){
					this.sign = posSign;
				}else{
					this.coord *= -1;
					this.sign = negSign;
				}
				
				this.deg = Math.floor(coord);
				coord = (coord - this.deg) * 60;
				this.min = Math.floor(coord);
				coord = (coord - this.min) * 60;
				this.sec = Math.floor(coord);
			}
		}
	}
}
